package 代码记录.校招笔试真题.笔试真题_2022.欧科云链12月;

/**
 * @author zx
 * @create 2022-11-30 16:12
 */
public class Test2 {
    /**
     * @return 暴力解法66.67%
     */
    public int planStock1 (int[][] order, int balance) {
        int res = 0;
        for(int i = 0;i < order.length;i++){
            int n = order[i][0] * order[i][1];
            if(balance >= n){
                balance -= n;
                res += order[i][1];
            }
        }
        return res;
    }
    public int planStock (int[][] order, int balance) {
        int res = 0;
        for(int i = 0;i < order.length;i++){
            int n = order[i][0] * order[i][1];
            if(balance >= n && helper(order,i,n,order[i][1])){
                balance -= n;
                res += order[i][1];
            }
        }
        return res;
    }
    private boolean helper(int[][] order, int i, int n, int k){
        boolean res = true;
        for(int j = i;j < order.length;j++){
            if(order[j][0] * order[j][1] < n && order[j][1] > k){
                res = false;
            }
        }
        return res;
    }
}
